package com.itany.controller;

import com.github.pagehelper.PageInfo;
import com.itany.pojo.Examine;
import com.itany.service.ExamineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import utils.AjaxResult;

import java.util.HashMap;
import java.util.Map;

/**
 * Author：汤小洋
 * Date：2019-09-18 下午6:28
 * Description：<描述>
 */
@Controller
@RequestMapping("/examine")
public class ExamineController {


    @Autowired
    private ExamineService examineService;

    @RequestMapping("findAll")
    @ResponseBody
    public Map<String,Object> findAll(@RequestParam(defaultValue="1")Integer page,
                                      @RequestParam(defaultValue="10")Integer rows){
        Map<String,Object> map = new HashMap<String, Object>();
        PageInfo<Examine> info=examineService.findAll(page, rows);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }


    @RequestMapping("findByCondition")
    @ResponseBody
    public Map<String,Object> findByCondition(@RequestParam(defaultValue="1")Integer page,
                                      @RequestParam(defaultValue="10")Integer rows,Examine examine){
        Map<String,Object> map = new HashMap<String, Object>();
        PageInfo<Examine> info=examineService.findByCondition(page, rows,examine);
        map.put("total", info.getTotal());
        map.put("rows", info.getList());
        return map;
    }



    @RequestMapping("/addInfo")
    @ResponseBody
    public AjaxResult addInfo( Examine examine,@RequestParam("bookid") Integer bookid){

        examine.setBookId(bookid);
        examineService.addInfo(examine);


        return AjaxResult.isOk();
    }
}